package com.example.springboottools.utils.image;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 
//public class ImageResizeExample {
//    public static void main(String[] args) {
//        try {
//            // 读取原始图片
//            BufferedImage originalImage = ImageIO.read(new File("original.jpg"));
// 
//            // 设置新的图片分辨率大小
//            int newWidth = 800;
//            int newHeight = 600;
// 
//            // 创建缩放后的图片
//            BufferedImage resizedImage = (BufferedImage) originalImage.getScaledInstance(newWidth, newHeight, BufferedImage.SCALE_SMOOTH);
// 
//            // 写入新的图片文件
//            ImageIO.write(resizedImage, "jpg", new File("resized.jpg"));
// 
//            System.out.println("图片分辨率转换完成。");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 
public class ImageComparator {
 
    public static boolean isImageEqual(File image1, File image2) throws IOException {
        BufferedImage img1 = ImageIO.read(image1);
        BufferedImage img2 = ImageIO.read(image2);
 
        if (img1.getWidth() != img2.getWidth() || img1.getHeight() != img2.getHeight()) {
            return false;
        }
 
        for (int y = 0; y < img1.getHeight(); y++) {
            for (int x = 0; x < img1.getWidth(); x++) {
                if (img1.getRGB(x, y) != img2.getRGB(x, y)) {
                    return false;
                }
            }
        }
        return true;
    }
 
    public static void main(String[] args) {
        try {
            File image1 = new File("C:\\Users\\SH102909\\Downloads\\cn1100124574EA_1_xnl.jpg");
            File image2 = new File("C:\\Users\\SH102909\\Downloads\\cn1100124574EA_8_xnl.jpg");
            boolean areEqual = isImageEqual(image1, image2);
            System.out.println("Images are equal: " + areEqual);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}